package javaobjectsandencapsulation.no6;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * 上机二
 * 根据宠物昵称查找宠物
 */
public class Test2 {
    public static void main(String[] args) {
        //初始化宠物
        Dog dog = new Dog("果冻", "拉布拉多", 10);
        Dog dog1 = new Dog("铛铛", "泰迪", 5);
        Dog dog2 = new Dog("麦吉", "哈士奇", 20);
        Dog dog3 = new Dog("小黑", "中华田园犬", 15);
        Dog dog4 = new Dog("布丁", "博美", 4);
        //Map接口声明 HashMap() 集合
        Map map = new HashMap();
        map.put("GD", dog);
        map.put("DD", dog1);
        map.put("MJ", dog2);
        map.put("XH", dog3);
        map.put("BD", dog4);
        System.out.print("请输入要查找的宠物简称(如:GD-果冻)：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.next();
        if (map.get(name) != null) {
            Dog dogs = (Dog) map.get(name);
            dogs.print();
        }else {
            System.out.println("错误:没有该宠物的存在!");
        }


    }
}
